package com.qing.controller;
import com.qing.domain.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.qing.service.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class MainController {
    private final NewsService newsService;
    @Autowired        //和@Repository一对，不能漏！！！！！
    public MainController(NewsService newsService){
        this.newsService=newsService;
    }


    @RequestMapping("/")       //只转 主页(有没有////都行)
    public String index(){return "index";}
    @RequestMapping("/news")    //转 新闻动态(有没有////都行)
    public String news(HttpServletRequest request){
      List<News> news = newsService.getAllNews();//为什么用的service？？
      request.setAttribute("news",news);
      System.out.println(news);
      return "news/news";
    }
    @RequestMapping("userLogin")//只转 新闻动态
    public String userLogin(){
        return "user/userLogin";
    }
    @RequestMapping("/toAddNews")
    public String userLogin(){
        return "news/addNews";
    }

}
